#pragma once

#include "ReadLinkAction.h"

#include "OutputPin.h"
#include "Property.h"

namespace uml {

ReadLinkAction::ReadLinkAction(const QString& umlType)
    : LinkAction(umlType) {}

void ReadLinkAction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    LinkAction::fromJson(json, errorList);
    result_ = JsonSerializable::create<OutputPin>(json.value("result"), errorList);

}

void ReadLinkAction::toJson(QJsonObject& json) {
    LinkAction::toJson(json);
    if (result_) {
        QJsonObject result_json;
        result_->toJson(result_json);
        json.insert("result", result_json);
    }
}

/// <summary>
/// openEnds
    /// Returns the ends corresponding to endData with no value InputPin. (A well-formed
    /// ReadLinkAction is constrained to have only one of these.)
/// </summary>
    /// <code>
    /// result = (endData->select(value=null).end->asOrderedSet())
    /// </code>
shared_ptr<vector<Property>> ReadLinkAction::openEnds() const
{
    return nullptr;
}

/// <summary>
/// result getter
/// The OutputPin on which the objects retrieved from the "open" end of those links
/// whose values on other ends are given by the endData.
/// </summary>
shared_ptr<OutputPin> ReadLinkAction::result() const {
    return result_;
}

/// <summary>
/// result setter
/// The OutputPin on which the objects retrieved from the "open" end of those links
/// whose values on other ends are given by the endData.
/// </summary>
void ReadLinkAction::setResult(shared_ptr<OutputPin> value) {
    result_ = value;
}

} // namespace uml
